﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.Spreadsheet;
using DevExpress.XtraEditors;
using EasyLottery.Core;

namespace EasyLottery.View
{
    public partial class FormImport : DevExpress.XtraEditors.XtraForm
    {
        private Worksheet worksheet;

        public Worksheet Worksheet
        {
            get { return worksheet; }
        }

        public FormImport()
        {
            InitializeComponent();
        }

        private void FormImport_Load(object sender, EventArgs e)
        {
            barButtonItem1.ItemClick += BarButtonItem1_ItemClick;
        }

        private void BarButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

            List<Person> personList = new List<Person>();

            worksheet = spreadsheetControl1.ActiveWorksheet;
            IList<Range> selectedRanges = worksheet.GetSelectedRanges();
            foreach (Range selectedRange in selectedRanges)
            {
                for (int i = selectedRange.TopRowIndex; i <= selectedRange.BottomRowIndex; i++)
                {
                    Person person = new Person();
                    person.ColumnIndex = i;
                    string displayInfo = null;
                    for (int j = selectedRange.LeftColumnIndex; j <= selectedRange.RightColumnIndex; j++)
                    {
                        if (j == selectedRange.LeftColumnIndex)
                        {
                            displayInfo += worksheet.GetCellValue(j, i);
                        }
                        else
                        {
                            displayInfo += "-" + worksheet.GetCellValue(j, i);
                        }
                    }

                    person.DisplayInfo = displayInfo;
                    personList.Add(person);
                }
            }
        }
    }
}